﻿
using LPP.Entity.Booking;
using LPP.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;


namespace LPP.Repository.BookingRepository;
public class BookingRepository : IBookingRepository
{

    private readonly SqlDbContext _context;

    public BookingRepository(SqlDbContext context)
    {
        _context = context;
    }

    public async Task<bool> AddBookingAsync(Booking booking)
    {
        await _context.Bookings.AddAsync(booking);
        return await _context.SaveChangesAsync() > 0;
    }

    public async Task<Booking> GetBookingByIdAsync(int id)
    {
        return await _context.Bookings.FindAsync(id);
    }

    public async Task<List<Booking>> GetAllBookingsAsync()
    {
        return await _context.Bookings.ToListAsync();
    }

    public async Task<bool> UpdateBookingAsync(Booking booking)
    {
        _context.Bookings.Update(booking);
        return await _context.SaveChangesAsync() > 0;
    }

    public async Task<bool> DeleteBookingAsync(int id)
    {
        var booking = await _context.Bookings.FindAsync(id);
        if (booking == null) return false;

        _context.Bookings.Remove(booking);
        return await _context.SaveChangesAsync() > 0;
    }
}
